package hello;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;

@Configuration
@ComponentScan("hello")
public class HelloConfig {

    @Bean
    public LettuceConnectionFactory connectionFactory(){

        LettuceConnectionFactory factory = new LettuceConnectionFactory("localhost",6379);
        return factory;
    }


    @Bean
    public StringRedisTemplate redisTemplate(){
        //StringRedisTemplate是RedisTemplate的子类，专门针对字符串操作
        StringRedisTemplate template = new StringRedisTemplate(connectionFactory());
        return  template;
    }

}
